<?php

namespace App\Service\UserCenter\v1_0_8;

use App\Constants\ErrorCode;
use App\Model\UserProfilePersonal;
use App\Service\BaseService;

/**
 * 绑定收款账户信息
 */
class AccountBindInfoService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $personInfo = UserProfilePersonal::getProfile($userId);

        if (!UserProfilePersonal::isFaceVerified($personInfo)) {
            return $this->setError(ErrorCode::NO_ID_VRFY, '请先完成实名认证～（如在认证审核中，请通过审核后再提现哦！）');
        }

        if (!UserProfilePersonal::isBindAccount($personInfo)) {
            // if (!$personInfo['bank_card']) {
            return $this->setError(ErrorCode::NO_BIND_ACCOUNT, '请先绑定您的收款账号!', [
                'real_name' => $personInfo ? $personInfo['real_name'] : ''
            ]);
        }
        return [
            // 'account_type' => $personInfo['alipay_account'] ? 0 : 1,
            // 'account' => $personInfo['alipay_account'] ?: $personInfo['bank_card'],
            'account_type' => $personInfo['bank_card'] ? 1 : 0,
            'account' => $personInfo['bank_card'] ?: $personInfo['alipay_account'],
            'real_name' => $personInfo['real_name'],
        ];
    }
}
